﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using BLL;
namespace LandAppraisal.Controllers
{
    public class AuthorityController : ApiController
    {
        AdminBLL bll = new AdminBLL();

        #region 获取权限列表
        /// <summary>
        /// 获取权限列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IEnumerable<SysAuthority> Get()
        {
            return bll.GetList<SysAuthority>();
        }
        #endregion

        #region 左侧导航树
        /// <summary>
        /// 左侧导航树
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        [HttpGet]
        public string Get(int roleid)
        {
            TreeNode tree = new TreeNode();
            List<SysAuthorityAndRoles> list = bll.GetListByRoleId(roleid).ToList();
            return tree.GetTreeJsonByList(list, 0);
        }
        #endregion

        #region 添加权限表
        /// <summary>
        /// 添加权限表
        /// </summary>
        /// <param name="value"></param>
        [HttpPost]
        public int Post([FromBody] SysAuthority authority)
        {
            return bll.Add(authority);
        }
        #endregion

        #region 修改权限信息
        /// <summary>
        /// 修改权限信息
        /// </summary>
        /// <param name="authority"></param>
        /// <returns></returns>
        [HttpPut]
        public bool Put([FromBody]SysAuthority authority)
        {
            return bll.Update<SysAuthority>(authority);
        }
        #endregion

        #region 删除权限
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public bool Delete(int id)
        {
            return bll.DeleteById<SysAuthority>(id);
        }
        #endregion

    }
}
